import {request} from 'umi';

/** 导入调拨单数据 POST /transfer/import */
export async function importTransfer(file: File, options?: { [key: string]: any }) {
  const formData = new FormData();
  formData.append('file', file);
  return request<BaseResponse<boolean>>('/api/transfer/import', {
    method: 'POST',
    data: formData,
    ...(options || {}),
  });
}

/** 添加调拨单 POST /transfer/add */
export async function addTransfer(body: TransferDTO, options?: { [key: string]: any }) {
  return request<BaseResponse<boolean>>('/api/transfer/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 分页查询调拨单列表 POST /transfer/list */
export async function listTransferOrderVoByPage(
  body: RequestParam<TransferOrderDto>,
  options?: { [key: string]: any },
) {
  return request<BaseResponse<IPage<TransferOrderVo>>>('/api/transfer/list', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 审批调拨单 POST /transfer/approval */
export async function approvalTransfer(
  id: string,
  options?: { [key: string]: any },
) {
  return request<BaseResponse<boolean>>('/api/transfer/approval', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      data: id,
    },
    ...(options || {}),
  });
}

/** 根据 ID 获取调拨单详细信息 GET /transfer/ */
export async function getTransferDetailsById(
  params: { id: string },
  options?: { [key: string]: any },
) {
  return request<BaseResponse<TransferOrderDetailsVo>>('/api/transfer/', {
    method: 'GET',
    params: params,
    ...(options || {}),
  });
}

/** 根据用料计划生成调拨单 POST /transfer/generate-by-plan */
export async function generateTransferOrderByPlan(
  originWarehouseId: string,
  targetWarehouseId: string,
  materialUsagePlanId: string,
  options?: { [key: string]: any }
) {
  return request<BaseResponse<boolean>>('/api/transfer/generate-by-plan', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      originWarehouseId,
      targetWarehouseId,
      materialUsagePlanId
    },
    ...(options || {}),
  });
}
